package com.mzx.javase.io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * 类描述：OutputStreamWriter，输出流，字符流到字节流的桥梁，传入一个文件输出路，可以指定输出的字符编码集
 *
 * @ClassName OutputStreamWriterTest
 * @Description TODO
 * @Author 马子鑫
 * @Date 2022/7/31 19:48
 * @Version 1.0
 */
public class OutputStreamWriterTest {
    public static void main(String[] args) {
        OutputStreamWriter outputStreamWriter = null;
        try {
            outputStreamWriter = new OutputStreamWriter(new FileOutputStream("gbkFile.txt"),"gbk");
            outputStreamWriter.write("您好");
            outputStreamWriter.flush();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (outputStreamWriter != null) {
                try {
                    outputStreamWriter.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
